/**   
 * @Title: ShiyixuanwuChooseBallSpace.java 
 * @Package com.esun.lottery.shiyixuanwu 
 * @Description: TODO(选球区域类) 
 * @author Miko baoz@500wan.com   
 * @date 2011-1-15 下午05:54:34  
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk;

import java.util.ArrayList;

import com.esun.ui.R;
import com.esun.util.log.EDebug;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @ClassName: ShiyixuanwuChooseBallSpace
 * @Description: TODO(选球区域的显示)
 * @author Miko baoz@500wan.com
 * @date 2011-1-15 下午05:54:34
 * 
 */

/*
 * 244 前一直选 11选5 是 245 前二直选 11选5 是 246 前三直选 11选5 是 247 前二组选 11选5 是 248 前三组选 11选5
 * 是 249 任选二 11选5 是 250 任选三 11选5 是 251 任选四 11选5 是 252 任选五 11选5 是 253 任选六 11选5 是
 * 254 任选七 11选5 是 255 任选八 11选5 是 256 混投 11选5 是 257 前二直选全选 11选5 是 258 前三直选全选 11选5
 * 是 259 前二直选和值 11选5 是 260 前二组选和值 11选5 是 261 前二组选胆拖 11选5 是 262 前三直选和值 11选5 是 263
 * 前三组选和值 11选5 是 264 前三组选胆拖 11选5 是 265 任选四胆拖 11选5 是 266 任选五胆拖 11选5 是 267 任选六胆拖
 * 11选5 是 268 任选七胆拖 11选5 是
 */
public class ShiyixuanwuChooseBallSpace implements GetTermInfoInBack, View.OnClickListener {

	/**
	 * <p>
	 * Title: ShiyixuanwuChooseBallSpace 构造函数
	 * </p>
	 * <p>
	 * Description: 接收创建实例时的属性值
	 * </p>
	 * 
	 * @param context
	 *            MainAct
	 * @param style
	 *            玩法代号 （1 - 8）
	 * @param detail
	 *            投注方式代号 （1 - 3）
	 */
	public ShiyixuanwuChooseBallSpace(Context context, View view, int style, int detail) {
		// TODO Auto-generated constructor stub

		this.context = context;

		this.view = view;

		inflater = ((Activity) context).getLayoutInflater();

		checkPlayFunction(style, detail);

		EDebug.o(this, "^^^^^^^^^^^^^^^^^^^^^^^^^^" + String.valueOf(howManyKeboard != 0));

		if (howManyKeboard != 0) {

			initKeyBoard(view);

			// doPrepare();
		}
		updateLossData(ShiyixuanwuLossData.getLossData().getSpace1(), ShiyixuanwuLossData.getLossData().getSpace2(), ShiyixuanwuLossData.getLossData().getSpace3(), ShiyixuanwuLossData.getLossData()
				.getFree());

	}

	private LayoutInflater inflater;

	// 需要的键盘个数
	private int howManyKeboard;

	// 选号区域的LinearLayout
	private LinearLayout keyBoardSpace;

	// MainAct
	Context context;

	// 所选球的号码
	private String[] space1;
	private String[] space2;
	private String[] space3;

	// 接收更新信息
	// public static Handler shiyixuanwuShowLossHandler = null;

	// 控件的arraylist <为了动态设置textView的文字>
	ArrayList<LinearLayout> alTV1 = new ArrayList<LinearLayout>();
	ArrayList<LinearLayout> alTV2 = new ArrayList<LinearLayout>();
	ArrayList<LinearLayout> alTV3 = new ArrayList<LinearLayout>();

	View view;

	private Object[] objAL = {
								alTV1,
								alTV2,
								alTV3 };

	/**
	 * @Title: checkPlayFunction
	 * @Description: TODO(检查显示区域需要几个键盘)
	 * @param @param style 玩法代号
	 * @param @param detail 投注方式代号
	 * @return void
	 */
	private void checkPlayFunction(int style, int detail) {

		if (style == 2 && detail == 2) {

			howManyKeboard = 2;
			EDebug.o(this, "this is loading keboard step in howManyKeboard ! this is " + String.valueOf(howManyKeboard));
			space1 = new String[11];
			space2 = new String[11];

		} else if (style == 3 && detail == 2) {

			howManyKeboard = 3;

			EDebug.o(this, "this is loading keboard step in howManyKeboard ! this is " + String.valueOf(howManyKeboard));

			space1 = new String[11];
			space2 = new String[11];
			space3 = new String[11];

		} else if (style == 0 || detail == 0) {

			howManyKeboard = 0;

			EDebug.o(this, "this is loading keboard step in howManyKeboard ! this is " + String.valueOf(howManyKeboard));

		} else {

			howManyKeboard = 1;

			EDebug.o(this, "this is loading keboard step in howManyKeboard ! this is " + String.valueOf(howManyKeboard));

			space1 = new String[11];
		}

		return;
	}

	/**
	 * @Title: initKeyBoard
	 * @Description: TODO(初始化键盘)
	 * @return void 返回类型
	 */
	private void initKeyBoard(View view) {

		EDebug.o(this, "init KeyBoard start !");

		keyBoardSpace = (LinearLayout) view.findViewById(R.id.shiyixuanwu_container_num_chooseSpace);

		keyBoardSpace.removeAllViews();

		for (int i = 0; i < howManyKeboard; i++) {
			LinearLayout aLine = (LinearLayout) inflater.inflate(R.layout.shiyixuanwu_keyboard, null);

			RelativeLayout aText = (RelativeLayout) inflater.inflate(R.layout.a_textview, null);
			TextView tvKeyboardNum = (TextView) aText.findViewById(R.id.oneTextView);

			String chnWord = "";
			if (i == 0) {
				chnWord = "一";
			} else if (i == 1) {
				chnWord = "二";
			} else if (i == 2) {
				chnWord = "三";
			}
			setKeyboardTxt(tvKeyboardNum, chnWord);

			aLine.setId(i + 1);
			aLine.addView(aText);

			aLine.setOrientation(LinearLayout.VERTICAL);

			LinearLayout eachKeyboard = (LinearLayout) getOneKeyboard(view, aLine, i);

			LinearLayout blank = (LinearLayout) inflater.inflate(R.layout.shiyixuanwu_keyboard_space, null);
			blank.addView(eachKeyboard);
			keyBoardSpace.addView(blank);
		}

		EDebug.o(this, "keyboard should shown" + String.valueOf(keyBoardSpace));

		EDebug.o(this, "init KeyBoard end !");

	}

	private void setKeyboardTxt(TextView tvKeyboardNum, String numChines) {

		int play = ShiyixuanwuPlayStyle.getPlayStyle().getStyle();
		int detail = ShiyixuanwuPlayStyle.getPlayStyle().getDetail();

		if (play == 1) {
			tvKeyboardNum.setText("前一");
		} else if (play == 2) {
			if (detail == 1) {
				tvKeyboardNum.setText("任选二");
			} else if (detail == 2) {

				tvKeyboardNum.setText("前" + numChines);
			} else if (detail == 3) {
				tvKeyboardNum.setText("前二组选");
			}
		} else if (play == 3) {
			if (detail == 1) {
				tvKeyboardNum.setText("任选三");
			} else if (detail == 2) {
				tvKeyboardNum.setText("前" + numChines);
			} else if (detail == 3) {
				tvKeyboardNum.setText("前三组选");
			}
		} else {
			tvKeyboardNum.setText(ShiyixuanwuPlayStyle.getPlayStyle().getStyleTxt());
		}

	}

	/**
	 * @Title: getEachKeyboard
	 * @Description: TODO(得到一个键盘)
	 * @return LinearLayout 键盘
	 */
	@SuppressWarnings("unchecked")
	private LinearLayout getOneKeyboard(View father, LinearLayout aKeyboard, int keyboardNum) {

		EDebug.o(this, "init getOneKeyboard start !");

		// 容纳下所有按钮需要的行数
		int lineCount = 1;

		// 每行按钮的个数
		int btnCounterForLine = 6;

		// 每一个按钮
		LinearLayout lineEachButton = (LinearLayout) ((Activity) context).getLayoutInflater().inflate(R.layout.shiyixuanwu_num_each, null);

		btnCounterForLine = ContainmentCounter.getCount(father, lineEachButton, R.drawable.numberchose_unselect_hvga_46x45, 15, 10, 7);

		EDebug.o(this, String.valueOf(btnCounterForLine) + "@@@@@@@@@!!!!!!!!!!!");

		lineCount = LittleUtils.getTotalLineCount(11, btnCounterForLine);
		EDebug.o(this, String.valueOf(lineCount) + "hahahaha!!!!!!!!!!!");

		for (int i = 1; i < lineCount + 1; i++) {
			LinearLayout btnLine = (LinearLayout) inflater.inflate(R.layout.a_linear, null);

			if (btnCounterForLine > 11) {
				btnCounterForLine = 11;
			}
			if (i == 1) {
				for (int j = 0; j < btnCounterForLine; j++) {

					LinearLayout eachButton = (LinearLayout) inflater.inflate(R.layout.shiyixuanwu_num_each, null);

					LayoutParams parEach = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
					if (j != btnCounterForLine - 1) {
						parEach.rightMargin = 7;
					} else {
						parEach.rightMargin = 0;
					}

					if (j == 0) {
						parEach.leftMargin = 5;
					} else {
						parEach.leftMargin = 0;
					}
					eachButton.setLayoutParams(parEach);

					eachButton.setId(j + 1);
					eachButton.setTag(false);

					TextView tvbtnTxt = (TextView) eachButton.findViewById(R.id.shiyixuanwu_num_each_text);
					TextView tvlossTxt = (TextView) eachButton.findViewById(R.id.shiyixuanwu_num_each_loss);

					((ArrayList<LinearLayout>) objAL[keyboardNum]).add(eachButton);

					tvbtnTxt.setText(String.valueOf(j + 1));
					tvlossTxt.setText("加载中...");

					eachButton.setOnClickListener(this);

					btnLine.addView(eachButton);

				}
				aKeyboard.addView(btnLine);
			} else if (i == 2) {
				for (int j = 0; j < 11 - btnCounterForLine; j++) {

					LinearLayout eachButton = (LinearLayout) inflater.inflate(R.layout.shiyixuanwu_num_each, null);

					LayoutParams parEach = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

					if (j != 11 - btnCounterForLine - 1) {
						parEach.rightMargin = 7;
					} else {
						parEach.rightMargin = 0;
					}

					if (j == 0) {
						parEach.leftMargin = 5;
					} else {
						parEach.leftMargin = 0;
					}
					eachButton.setLayoutParams(parEach);

					eachButton.setId(btnCounterForLine + 1 + j);
					eachButton.setTag(false);

					TextView tvbtnTxt = (TextView) eachButton.findViewById(R.id.shiyixuanwu_num_each_text);
					TextView tvlossTxt = (TextView) eachButton.findViewById(R.id.shiyixuanwu_num_each_loss);

					((ArrayList<LinearLayout>) objAL[keyboardNum]).add(eachButton);

					tvbtnTxt.setText(String.valueOf(btnCounterForLine + j + 1));
					tvlossTxt.setText("加载中...");

					eachButton.setOnClickListener(this);

					LayoutParams parLine = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
					parLine.topMargin = 5;
					btnLine.setLayoutParams(parLine);
					btnLine.addView(eachButton);
				}
				aKeyboard.addView(btnLine);
			}
		}
		EDebug.o(this, "init getOneKeyboard end !");
		aKeyboard.setBackgroundResource(R.drawable.shiyixuanwu_keyboard_shape_file);

		return aKeyboard;
	}

	/**
	 * @Title: getSelectedNum
	 * @Description: TODO(得到选球号码)
	 * @param num
	 *            控件id
	 * @return String 所选号码
	 */
	private int getSelectedNum(int num) {
		return num % 100;
	}

	/**
	 * @Title: setSelectedNum
	 * @Description: TODO(保存所选号码)
	 * @param spaceNum
	 *            区域号
	 * @param num
	 *            所选号码
	 * @return void 返回类型
	 */
	private void setSelectedNum(int spaceNum, int num) {

		if (spaceNum == 1) {

			space1[num - 1] = String.valueOf(num);

			// for(int i=0;i<space1.length;i++){
			// EDebug.o(this,"space1 include : " + space1[i]);
			// }
			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace1(space1);

		} else if (spaceNum == 2) {

			space2[num - 1] = String.valueOf(num);

			// for(int i=0;i<space2.length;i++){
			// EDebug.o(this,"space2 include : " + space2[i]);
			// }

			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace2(space2);

		} else if (spaceNum == 3) {

			space3[num - 1] = String.valueOf(num);

			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace3(space3);
		}

	}

	public void setNumSelected(String[] space1, String[] space2, String[] space3) {

		if (space1 != null) {
			for (int i = 0; i < space1.length; i++) {
				setSelectedNum(1, Integer.parseInt(space1[i]));
				setOneNumSelected(alTV1, Integer.parseInt(space1[i]));
			}
		}

		if (space2 != null) {
			for (int i = 0; i < space2.length; i++) {
				setSelectedNum(2, Integer.parseInt(space2[i]));
				setOneNumSelected(alTV2, Integer.parseInt(space2[i]));
			}
		}

		if (space3 != null) {
			for (int i = 0; i < space3.length; i++) {
				setSelectedNum(3, Integer.parseInt(space3[i]));
				setOneNumSelected(alTV3, Integer.parseInt(space3[i]));
			}
		}

		if (howManyKeboard == 3) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getHead3VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else if (howManyKeboard == 2) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getHead2VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getDrect1VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getFreeVoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		}
	}

	private void setRandomNum(StringBuilder sbRandom) {

		if (howManyKeboard == 1) {
			updateKeyboard(sbRandom, alTV1);
		} else if (howManyKeboard == 2) {
			updateKeyboard(sbRandom, alTV1, alTV2);
		} else if (howManyKeboard == 3) {
			updateKeyboard(sbRandom, alTV1, alTV2, alTV3);
		}

	}

	private void setOneNumSelected(ArrayList<LinearLayout> al, int num) {
		((LinearLayout) al.get(num - 1)).getChildAt(0).setBackgroundResource(R.drawable.numberchose_select_hvga_46x45);
		((TextView) ((LinearLayout) ((LinearLayout) al.get(num - 1)).getChildAt(0)).getChildAt(0)).setTextColor(Color.WHITE);
		((LinearLayout) al.get(num - 1)).getChildAt(1).setBackgroundResource(R.drawable.numberchose_select_btm_46x45);
		al.get(num - 1).setTag(true);
	}

	private void updateKeyboard(StringBuilder sbRandom, ArrayList<LinearLayout> al) {
		String[] temp = sbRandom.toString().split(",");

		for (int i = 0; i < temp.length; i++) {
			int k = Integer.parseInt(temp[i]);
			setOneNumSelected(al, k);
			setSelectedNum(1, k);
		}
	}

	private void updateKeyboard(StringBuilder sbRandom, ArrayList<LinearLayout> al1, ArrayList<LinearLayout> al2) {
		String[] temp = sbRandom.toString().split(",");
		setOneNumSelected(al1, Integer.parseInt(temp[0]));
		setSelectedNum(1, Integer.parseInt(temp[0]));

		setOneNumSelected(al2, Integer.parseInt(temp[1]));
		setSelectedNum(2, Integer.parseInt(temp[1]));
	}

	private void updateKeyboard(StringBuilder sbRandom, ArrayList<LinearLayout> al1, ArrayList<LinearLayout> al2, ArrayList<LinearLayout> al3) {
		String[] temp = sbRandom.toString().split(",");
		setOneNumSelected(al1, Integer.parseInt(temp[0]));
		setSelectedNum(1, Integer.parseInt(temp[0]));

		setOneNumSelected(al2, Integer.parseInt(temp[1]));
		setSelectedNum(2, Integer.parseInt(temp[1]));

		setOneNumSelected(al3, Integer.parseInt(temp[2]));
		setSelectedNum(3, Integer.parseInt(temp[2]));
	}

	/**
	 * @Title: updateLossData
	 * @Description: TODO(更新遗漏数据)
	 * @param 设定文件
	 * @return void 返回类型
	 * @throws
	 */
	public void updateLossData(String[] space1, String[] space2, String[] space3, String[] free) {

		// 前一直选
		if (howManyKeboard == 1 && ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {
			if (ShiyixuanwuLossData.getLossData().getSpace1()[0] != null) {
				for (int i = 0; i < alTV1.size(); i++) {

					int lossNum = Integer.parseInt(space1[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space1[i] + "期");
					}
					if (lossNum > 10) {
//						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
					// ((TextView)alTV1.get(i).getChildAt(1)).setText(space1[i]);
				}
			}

		}
		// 前一其他
		else if (howManyKeboard == 1 && ShiyixuanwuPlayStyle.getPlayStyle().getDetail() != 2) {
			if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 3) {
				if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 2) {

					String[] temp = ShiyixuanwuLossData.getLossData().getZu2();

					for (int i = 0; i < alTV1.size(); i++) {

						int lossNum = Integer.parseInt(temp[i]);

						if (lossNum > 99) {
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
						} else {
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + temp[i] + "期");
						}
						if (lossNum > 10) {
//							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
						}
						// alTV1.get(i).setText(free[i]);
					}
				} else if (ShiyixuanwuPlayStyle.getPlayStyle().getStyle() == 3) {
					String[] temp = ShiyixuanwuLossData.getLossData().getZu3();

					for (int i = 0; i < alTV1.size(); i++) {

						int lossNum = Integer.parseInt(temp[i]);

						if (lossNum > 99) {
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
						} else {
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + temp[i] + "期");
						}
						if (lossNum > 10) {
//							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
							((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
						}
						// alTV1.get(i).setText(free[i]);
					}
				}
			} else if (ShiyixuanwuLossData.getLossData().getFree()[0] != null) {

				for (int i = 0; i < alTV1.size(); i++) {

					int lossNum = Integer.parseInt(free[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + free[i] + "期");
					}
					if (lossNum > 10) {
//						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
					// alTV1.get(i).setText(free[i]);
				}

			}
		}
		// 前二直选
		else if (howManyKeboard == 2) {
			if (ShiyixuanwuLossData.getLossData().getSpace1()[0] != null && ShiyixuanwuLossData.getLossData().getSpace2()[0] != null) {
				for (int i = 0; i < alTV1.size(); i++) {

					int lossNum = Integer.parseInt(space1[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space1[i] + "期");
					}
					if (lossNum > 10) {
//						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
				}
				for (int i = 0; i < alTV2.size(); i++) {

					int lossNum = Integer.parseInt(space2[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space2[i] + "期");
					}

					if (lossNum > 10) {
//						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
//						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.WHITE);
					}
				}
			}

		}
		// 前三直选
		else if (howManyKeboard == 3) {
			if (ShiyixuanwuLossData.getLossData().getSpace1()[0] != null && ShiyixuanwuLossData.getLossData().getSpace2()[0] != null && ShiyixuanwuLossData.getLossData().getSpace3()[0] != null) {
				for (int i = 0; i < alTV1.size(); i++) {

					int lossNum = Integer.parseInt(space1[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space1[i] + "期");
					}

					if (Integer.parseInt(space1[i]) > 10) {
						// ((TextView) ((LinearLayout)
						// alTV1.get(i).getChildAt(1)).getChildAt(0))
						// .setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV1.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
				}
				for (int i = 0; i < alTV2.size(); i++) {

					int lossNum = Integer.parseInt(space2[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space2[i] + "期");
					}

					if (Integer.parseInt(space2[i]) > 10) {
						// ((TextView) ((LinearLayout)
						// alTV2.get(i).getChildAt(1)).getChildAt(0))
						// .setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV2.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
				}
				for (int i = 0; i < alTV3.size(); i++) {

					int lossNum = Integer.parseInt(space3[i]);

					if (lossNum > 99) {
						((TextView) ((LinearLayout) alTV3.get(i).getChildAt(1)).getChildAt(0)).setText("漏99+期");
					} else {
						((TextView) ((LinearLayout) alTV3.get(i).getChildAt(1)).getChildAt(0)).setText("漏" + space3[i] + "期");
					}

					if (lossNum > 10) {
						// ((TextView) ((LinearLayout)
						// alTV3.get(i).getChildAt(1)).getChildAt(0))
						// .setBackgroundResource(R.drawable.missnumber_overflow_hvga_42x12);
						((TextView) ((LinearLayout) alTV3.get(i).getChildAt(1)).getChildAt(0)).setTextColor(Color.RED);
					}
				}
			}

		}

	}

	/**
	 * @Title: removeSelectedNum
	 * @Description: TODO(移去所选号码)
	 * @param spaceNum
	 *            区域号
	 * @param num
	 *            所选号码
	 * @return void 返回类型
	 */
	private void removeSelectedNum(int spaceNum, int num) {

		EDebug.o(this, "Doing remove");

		if (spaceNum == 1) {
			space1[num - 1] = null;

			for (int i = 0; i < space1.length; i++) {
				EDebug.o(this, "space1 include : " + space1[i]);
			}
			EDebug.o(this, "Doing refresh space1");
			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace1(space1);

		} else if (spaceNum == 2) {

			space2[num - 1] = null;

			for (int i = 0; i < space2.length; i++) {
				EDebug.o(this, "space2 include : " + space2[i]);
			}
			EDebug.o(this, "Doing refresh space2");
			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace2(space2);

		} else if (spaceNum == 3) {

			space3[num - 1] = null;

			for (int i = 0; i < space3.length; i++) {
				EDebug.o(this, "space3 include : " + space3[i]);
			}
			EDebug.o(this, "Doing refresh space3");
			ShiyixuanwuBuyingInfo.getBuyingInfo().setSpace3(space3);
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		EDebug.o(this, "u are clicking parent view's id is : " + String.valueOf(((View) v.getParent().getParent()).getId()));
		EDebug.o(this, "u are clicking view's id is : " + String.valueOf(v.getId()));
		EDebug.o(this, "and the view's tag is : " + v.getTag());

		int id = v.getId();

		if (!(Boolean) v.getTag()) {

			((LinearLayout) v).getChildAt(0).setBackgroundResource(R.drawable.numberchose_select_hvga_46x45);
			((TextView) ((LinearLayout) ((LinearLayout) v).getChildAt(0)).getChildAt(0)).setTextColor(Color.WHITE);
			((LinearLayout) v).getChildAt(1).setBackgroundResource(R.drawable.numberchose_select_btm_46x45);
			v.setTag(true);

			setSelectedNum(((View) v.getParent().getParent()).getId(), getSelectedNum(id));

			EDebug.o(this, "the space num " + String.valueOf(((View) v.getParent().getParent()).getId()));
			EDebug.o(this, "the num is : " + getSelectedNum(id));
		} else {
			v.setTag(false);
			((LinearLayout) v).getChildAt(0).setBackgroundResource(R.drawable.numberchose_unselect_hvga_46x45);
			((TextView) ((LinearLayout) ((LinearLayout) v).getChildAt(0)).getChildAt(0)).setTextColor(Color.BLACK);
			((LinearLayout) v).getChildAt(1).setBackgroundResource(R.drawable.missnumber_hvga_42x12);

			EDebug.o(this, "Do remove");
			removeSelectedNum(((View) v.getParent().getParent()).getId(), getSelectedNum(id));

			EDebug.o(this, "the space num " + String.valueOf(((View) v.getParent().getParent()).getId()));
			EDebug.o(this, "the num is : " + getSelectedNum(id));
		}

		if (howManyKeboard == 3) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getHead3VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else if (howManyKeboard == 2) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getHead2VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else if (ShiyixuanwuPlayStyle.getPlayStyle().getDetail() == 2) {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getDrect1VoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		} else {

			ShiyixuanwuBuyingInfo.getBuyingInfo().setVoteLine(ShiyixuanwuUtils.getFreeVoteLineCount());
			ShiyixuanwuBuyingInfo.getBuyingInfo().showVoteLine();
			ShiyixuanwuBuyingInfo.getBuyingInfo().showMoney();

		}
	}

	@Override
	public boolean doPrepare() {

		return false;
	}

	@Override
	public void showTermInfo() {
		// TODO Auto-generated method stub

		updateLossData(ShiyixuanwuLossData.getLossData().getSpace1(), ShiyixuanwuLossData.getLossData().getSpace2(), ShiyixuanwuLossData.getLossData().getSpace3(), ShiyixuanwuLossData.getLossData()
				.getFree());
	}

	/**
	 * @Title: reLoad
	 * @Description: TODO(重新加载该页面)
	 * @param context
	 * @param view
	 *            设定文件
	 * @return void
	 */
	public void reLoad(Context context, View view, StringBuilder sbRandom) {
		ShiyixuanwuContainer.shiyixuanwuChooseBallSpace = new ShiyixuanwuChooseBallSpace(context, view, ShiyixuanwuPlayStyle.getPlayStyle().getStyle(), ShiyixuanwuPlayStyle.getPlayStyle().getDetail());
		if (sbRandom != null) {
			ShiyixuanwuContainer.shiyixuanwuChooseBallSpace.setRandomNum(sbRandom);
		}

	}
}
